package com.qidian.mes.om.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qidian.mes.om.mapper.SysUserMapper;
import com.qidian.mes.om.service.SysUserService;
import com.qidian.mes.pojo.SysUser;
import com.qidian.mes.util.pojo.MESResult;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author 戴着假发的程序员
 * @Company 起点编程
 * @Time 2023/11/2 9:31
 * @Description
 */
@Service
public class SysUserServiceImpl implements SysUserService {
    @Autowired
    private SysUserMapper userMapper;
    @Override
    public MESResult save(SysUser user) {
        // 使用Spring提供的工具对密码进行MD5加密。
        String password = DigestUtils.md5Hex(user.getUserPass().getBytes());
        // 我们将加密后的密码保存到数据。
        user.setUserPass(password);
        return MESResult.updateIsOk(userMapper.save(user));
    }

    @Override
    public MESResult list(int page, int limit,SysUser user) {
        PageHelper.startPage(page,limit);
        List<SysUser> list = userMapper.list(user);
        return MESResult.ok(new PageInfo<>(list));
    }
}
